home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / ProcDoggie 1.0a6 / UDialogUtils.p < prev    next >
Encoding:
Text File  |  1991-02-07  |  9.8 KB  |  229 lines  |  [TEXT/MPS ]

  1. UNIT UDialogUtils;
  2.  
  3. {-------------------------------------------------------------------------------
  4. #
  5. #    Apple Macintosh Developer Technical Support
  6. #
  7. #    Interfaces for the dialog utilities
  8. #
  9. #    Program:    ProcDoggie
  10. #    File:        UDialogUtils.p - Pascal Implementation
  11. #
  12. #    by:        Forrest Tanaka
  13. #
  14. #    Copyright © 1988-1991 Apple Computer, Inc.
  15. #    All rights reserved.
  16. #
  17. --------------------------------------------------------------------------------
  18. #
  19. # This unit is an embryonic version of an alternative to the Dialog Manager.
  20. # Why replace the Dialog Manager?  For dialogs with just a few basic items like
  21. # some static text and some buttons, the Dialog Manager isn’t too bad.  It still
  22. # doesn’t handle low-memory situations at all well nor does it handle cases in
  23. # which some resources are missing with much grace, but a small dialog shouldn’t
  24. # have too many problems with low-memory situations and clever memory
  25. # management can avoid all problems, and missing resources is an anomalous
  26. # situation.  The Dialog Manager exposes its problems once a dialog starts to
  27. # get a bit complicated.  User items and controls become difficult to manage,
  28. # and even something as simple as a static text item that’s in a different size
  29. # or style becomes a major hassle to implement.  The ictb mechanism introduced
  30. # on Color QuickDraw machines was supposed to make it easier to specify static
  31. # and edit text styles, but this mechanism is so buggy that it’s useless in my
  32. # opinion.  Another problem with the Dialog Manager is its slow performance when
  33. # drawing items.  Technical Note #203 “Don’t Abuse the Managers” has many words
  34. # of wisdom when it comes to the Dialog Manager, like don’t use it.
  35. #
  36. # Of course, the usual reply we get to this is, “But ResEdit’s DITL editor makes
  37. # arranging dialogs so easy!”  This is true, and I think it’s a compelling
  38. # argument.  This also makes localization very easy, which isn’t a trivial
  39. # concern.  But who said that only the Dialog Manager can read DITLs?  The
  40. # structure of a DITL is very well-defined, and couldn’t possibly change without
  41. # breaking every program that put up an alert box.  DITL resources aren’t that
  42. # complicated, and your own program can read them as well as the Dialog
  43. # Manager——better probably.
  44. #
  45. # That’s what this unit does.  It reads in a DITL, creates an internal item list
  46. # based on what it found in the DITL, then attaches this item list to the
  47. # "items" field of a DialogRecord.  This unit also contains routines to draw the
  48. # items and routines to set static text items.  And it does this while checking
  49. # for errors; what a concept!
  50. #
  51. # But, as I said, this unit is very embryonic.  The first time I tried this, I
  52. # made it very complete, but I also made it much, much harder to use than the
  53. # Dialog Manager.  So, I almost completely stripped it for the purposes of this
  54. # sample application.  Now, it only handles static text items and buttons, and
  55. # it no longer handles modal dialogs.  Eventually, I want to give this the full
  56. # functionality of the real Dialog Manager.
  57. #
  58. # One capability this unit has that the Dialog Manager doesn’t implement is
  59. # style information for static text items.  I don’t mean one static text item
  60. # with multiple text styles.  I mean different items can have different text
  61. # styles.  Doing this through the Dialog Manager involves much more work than
  62. # it should.  The way I do this while keeping the DITL structure is to use the
  63. # four bytes used for a placeholder for handle or procedure pointer in Inside
  64. # Macintosh I page 427.  If you want static text items displayed in the standard
  65. # font, style, and justification, then just leave these four bytes set to 0.  If
  66. # you want to specify the type face, style, size, and line justification, then
  67. # each of these four bytes can hold each of these pieces of information.
  68. #
  69. # The first byte holds a font index.  This isn’t a font number because, as
  70. # Technical Note #191 “Font Names” says, it isn’t nice to save font numbers.
  71. # This font index is an index into a STR# resource which contains the names of
  72. # whatever fonts you want to use in this dialog.  For example, if the second
  73. # string in the STR# resource is "Monaco", then a 2 placed into the font index
  74. # field will cause the DrawDialogItems routine defined in this unit to display
  75. # that static text item in Monaco.  The STR# resource should have a resource ID
  76. # of 0.  This lets all dialog boxes use the same font list.  You can override
  77. # this font list by specifying a STR# resource with an ID equal to the resource
  78. # ID of the DITL being read.  In this way, you can provide a STR# resource ID 0
  79. # that contains the default font list, and then provide special font lists for
  80. # for specific DITLs.
  81. #
  82. # The second byte holds the style (“face” according to QuickDraw) of the static
  83. # text item.  This holds the same value as the Style type.  The third byte
  84. # contains the point size of the static text.  The point size is limited to 255,
  85. # which shouldn’t be a problem.  The last byte contains the justification of the
  86. # static text.  -2 means left justification, -1 means right justification, 0
  87. # means default justification, and 1 means center justification.
  88. #
  89. -------------------------------------------------------------------------------}
  90. {[j=20/57/1$] Pasmat Options}
  91.  
  92.  
  93. INTERFACE
  94.  
  95.  
  96. (*******************************************************************************
  97. * Used Units
  98. *******************************************************************************)
  99.  
  100.     USES
  101.         (* Group 1 *)
  102.          Types
  103.         ,QuickDraw
  104.  
  105.         (* Group 2 *)
  106.         ,Controls
  107.         ,Errors
  108.         ,Events
  109.         ,Fonts
  110.         ,Memory
  111.         ,Resources
  112.         ,TextEdit
  113.         ,ToolUtils
  114.  
  115.         (* Group 3 *)
  116.         ,Windows
  117.  
  118.         (* Group 4 *)
  119.         ,Dialogs
  120.  
  121.         (* Application *)
  122.         ,UEmergMem
  123.         ;
  124.  
  125.  
  126. (*******************************************************************************
  127. * Constants
  128. *******************************************************************************)
  129.  
  130.     CONST
  131.         kNoItem = -1; {No dialog item is applicable or end of dialog item list}
  132.  
  133.  
  134. (*******************************************************************************
  135. * Types
  136. *******************************************************************************)
  137.  
  138.     TYPE
  139.         (* Type information for static text items *)
  140.         TypeInfoRec = RECORD
  141.             typeFace:  Integer; {Font number of text}
  142.             typeSize:  Integer; {Font size of text}
  143.             textJust:  Integer; {Justification of text}
  144.             typeStyle: Style;   {Font style of text}
  145.         END;
  146.  
  147.  
  148. (*******************************************************************************
  149. * InstallDialogItems - Install a DITL into a dialog window
  150. *
  151. * This routine is called to install a DITL into the dialog window specified by
  152. * "aDialog".  The resource ID of the desired DITL is specified by "itemListNum".
  153. * InstallDialogItems returns noErr if the item list was successfully created and
  154. * attached to aDialog, otherwise, an operating system error code is returned.
  155. *******************************************************************************)
  156.  
  157.     FUNCTION InstallDialogItems (aDialog:     DialogPtr;
  158.                                  itemListNum: Integer): OSErr;
  159.  
  160.  
  161. (*******************************************************************************
  162. * SetStatTextItem - Set a static text dialog item to the specified text
  163. *
  164. * This routine sets the text of a static text item to the text pointed to by
  165. * "textPtr" and having the length "textLength".  "aDialog" is a pointer to the
  166. * dialog box that this is being done in, and "itemNum" is the item number of the
  167. * static text item to set.  If that item isn’t actually a static text item, then
  168. * nothing is done.  If there isn’t enough memory to put the text into the static
  169. * text item, then nothing is done.
  170. *******************************************************************************)
  171.  
  172.     PROCEDURE SetStatTextItem (aDialog:    DialogPtr;
  173.                                itemNum:    Integer;
  174.                                textPtr:    Ptr;
  175.                                textLength: Integer);
  176.  
  177.  
  178. (*******************************************************************************
  179. * GetStatTextFontInfo - Get font information for a static text item
  180. *
  181. * This routine gets the font information for the static text item with an item
  182. * number of "itemNum" in the dialog specified by "aDialog".  This font
  183. * information is returned in "typeInfo".  The the specified item isn’t a static
  184. * text item, then nothing is done.
  185. *******************************************************************************)
  186.  
  187.     PROCEDURE GetStatTextFontInfo (aDialog:      DialogPtr;
  188.                                    itemNum:      Integer;
  189.                                    VAR typeInfo: TypeInfoRec);
  190.  
  191.  
  192. (*******************************************************************************
  193. * DrawDialogItems - Draw all standard dialog items
  194. *
  195. * All standard dialog items in the dialog box pointed to by "aDialog" are drawn.
  196. *******************************************************************************)
  197.  
  198.     PROCEDURE DrawDialogItems (aDialog: DialogPtr);
  199.  
  200.  
  201. (*******************************************************************************
  202. * GetDialogItemRect - Get the item rectangle of a specified dialog item
  203. *
  204. * This routine gets the item rectangle of the dialog item in the dialog box
  205. * specified by "aDialog" and having an item number of "itemNum".  This rectangle
  206. * is returned in "itemRect".
  207. *******************************************************************************)
  208.  
  209.     PROCEDURE GetDialogItemRect (aDialog:      DialogPtr;
  210.                                  itemNum:      Integer;
  211.                                  VAR itemRect: Rect);
  212.  
  213.  
  214. (*******************************************************************************
  215. * DisposeDialogItems - Dispose of all dialog items in the specified dialog box
  216. *
  217. * This routine disposes of the memory used by all the dialog items in the dialog
  218. * box specified by "aDialog".  The item list itself is also deallocated.
  219. *******************************************************************************)
  220.  
  221.     PROCEDURE DisposeDialogItems (aDialog: DialogPtr);
  222.  
  223.  
  224. IMPLEMENTATION
  225.  
  226.     {$I UDialogUtils.inc1.p}
  227.  
  228. END.
  229.